<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Medium
  </div>
  <div>
   <h1 class="question_title">
    885. Exam Room
   </h1>
   <p>
    In an exam room, there are
    <code>
     N
    </code>
    seats in a single row, numbered
    <code>
     0, 1, 2, ..., N-1
    </code>
    .
   </p>
   <p>
    When a student enters the room, they must sit in the seat that maximizes the distance to the closest person.&nbsp; If there are multiple such seats, they sit in the seat with the lowest number.&nbsp; (Also, if no one is in the room, then the student sits at seat number 0.)
   </p>
   <p>
    Return a class
    <code>
     ExamRoom(int N)
    </code>
    &nbsp;that exposes two functions:
    <code>
     ExamRoom.seat()
    </code>
    &nbsp;returning an
    <code>
     int
    </code>
    &nbsp;representing what seat the student sat in, and
    <code>
     ExamRoom.leave(int p)
    </code>
    &nbsp;representing that the student in seat number
    <code>
     p
    </code>
    &nbsp;now leaves the room.&nbsp; It is guaranteed that any calls to
    <code>
     ExamRoom.leave(p)
    </code>
    have a student sitting in seat
    <code>
     p
    </code>
    .
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     Example 1:
    </strong>
   </p>
   <pre>
<strong>Input: </strong><span id="example-input-1-1">["ExamRoom","seat","seat","seat","seat","leave","seat"]</span>, <span id="example-input-1-2">[[10],[],[],[],[],[4],[]]</span>
<strong>Output: </strong><span id="example-output-1">[null,0,9,4,2,null,5]</span>
<span><strong>Explanation</strong>:
ExamRoom(10) -&gt; null
seat() -&gt; 0, no one is in the room, then the student sits at seat number 0.
seat() -&gt; 9, the student sits at the last seat number 9.
seat() -&gt; 4, the student sits at the last seat number 4.
seat() -&gt; 2, the student sits at the last seat number 2.
leave(4) -&gt; null
seat() -&gt; 5, the student sits at the last seat number 5.</span>
</pre>
   <p>
    <span>
     ​​​​​​​
    </span>
   </p>
   <p>
    <strong>
     Note:
    </strong>
   </p>
   <ol>
    <li>
     <code>
      1 &lt;= N &lt;= 10^9
     </code>
    </li>
    <li>
     <code>
      ExamRoom.seat()
     </code>
     and
     <code>
      ExamRoom.leave()
     </code>
     will be called at most
     <code>
      10^4
     </code>
     times across all test cases.
    </li>
    <li>
     Calls to
     <code>
      ExamRoom.leave(p)
     </code>
     are guaranteed to have a student currently sitting in seat number
     <code>
      p
     </code>
     .
    </li>
   </ol>
  </div>
  <div>
   <h1 class="question_title">
    885. 考场就座
   </h1>
   <p>
    在考场里，一排有&nbsp;
    <code>
     N
    </code>
    &nbsp;个座位，分别编号为&nbsp;
    <code>
     0, 1, 2, ..., N-1
    </code>
    &nbsp;。
   </p>
   <p>
    当学生进入考场后，他必须坐在能够使他与离他最近的人之间的距离达到最大化的座位上。如果有多个这样的座位，他会坐在编号最小的座位上。(另外，如果考场里没有人，那么学生就坐在 0 号座位上。)
   </p>
   <p>
    返回&nbsp;
    <code>
     ExamRoom(int N)
    </code>
    &nbsp;类，它有两个公开的函数：其中，函数&nbsp;
    <code>
     ExamRoom.seat()
    </code>
    &nbsp;会返回一个&nbsp;
    <code>
     int
    </code>
    &nbsp;（整型数据），代表学生坐的位置；函数&nbsp;
    <code>
     ExamRoom.leave(int p)
    </code>
    &nbsp;代表坐在座位
    <code>
     p
    </code>
    上的学生现在离开了考场。请确保每次调用&nbsp;
    <code>
     ExamRoom.leave(p)
    </code>
    &nbsp;时都有学生坐在座位&nbsp;
    <code>
     p
    </code>
    &nbsp;上。
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     示例：
    </strong>
   </p>
   <pre><strong>输入：</strong>["ExamRoom","seat","seat","seat","seat","leave","seat"], [[10],[],[],[],[],[4],[]]
<strong>输出：</strong>[null,0,9,4,2,null,5]
<strong>解释：</strong>
ExamRoom(10) -&gt; null
seat() -&gt; 0，没有人在考场里，那么学生坐在 0 号座位上。
seat() -&gt; 9，学生最后坐在 9 号座位上。
seat() -&gt; 4，学生最后坐在 4 号座位上。
seat() -&gt; 2，学生最后坐在 2 号座位上。
leave(4) -&gt; null
seat() -&gt; 5，学生最后坐在 5 号座位上。
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     提示：
    </strong>
   </p>
   <ol>
    <li>
     <code>
      1 &lt;= N &lt;= 10^9
     </code>
    </li>
    <li>
     在所有的测试样例中&nbsp;
     <code>
      ExamRoom.seat()
     </code>
     &nbsp;和&nbsp;
     <code>
      ExamRoom.leave()
     </code>
     &nbsp;最多被调用&nbsp;
     <code>
      10^4
     </code>
     &nbsp;次。
    </li>
    <li>
     调用&nbsp;
     <code>
      ExamRoom.leave(p)
     </code>
     &nbsp;时需要确保当前有学生坐在座位
     <code>
      p
     </code>
     上。
    </li>
   </ol>
  </div>
 </body>
</html>